﻿<UserControl x:Class="GSF.TimeSeries.UI.UserControls.AlarmStatusUserControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" d:DesignHeight="650" d:DesignWidth="850"
             xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:uc="clr-namespace:GSF.TimeSeries.UI.UserControls"
             xmlns:tsfBinding="clr-namespace:GSF.TimeSeries.UI.Binding;assembly=GSF.TimeSeries.UI"
             xmlns:tsf="clr-namespace:GSF.TimeSeries.UI"
             Background="Transparent" Loaded="AlarmStatusUserControl_Loaded" Unloaded="AlarmStatusUserControl_Unloaded" PreviewKeyDown="AlarmStatusUserControl_PreviewKeyDown">

    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/GSF.TimeSeries.UI.WPF;Component/Resources/CommonResource.xaml" />
            </ResourceDictionary.MergedDictionaries>

            <Style TargetType="sdk:DataGridCell" x:Key="AlarmCellStyle">
                <Style.Triggers>
                    <Trigger Property="sdk:DataGridCell.IsSelected" Value="True">
                        <Setter Property="Background" Value="#22000000"/>
                        <Setter Property="BorderBrush" Value="#FF9EA7BF"/>
                    </Trigger>
                </Style.Triggers>
            </Style>

            <Style x:Key="CenterAlignAlarmCellStyle" TargetType="sdk:DataGridCell">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type DataGridCell}">
                            <Grid Background="{TemplateBinding Background}">
                                <ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center" />
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
                <Style.Triggers>
                    <Trigger Property="sdk:DataGridCell.IsSelected" Value="True">
                        <Setter Property="Background" Value="#22000000"/>
                        <Setter Property="BorderBrush" Value="#FF9EA7BF"/>
                    </Trigger>
                </Style.Triggers>
            </Style>

            <Style x:Key="RightAlignAlarmCellStyle" TargetType="sdk:DataGridCell">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type DataGridCell}">
                            <Grid Background="{TemplateBinding Background}">
                                <ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Right" />
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
                <Style.Triggers>
                    <Trigger Property="sdk:DataGridCell.IsSelected" Value="True">
                        <Setter Property="Background" Value="#22000000"/>
                        <Setter Property="BorderBrush" Value="#FF9EA7BF"/>
                    </Trigger>
                </Style.Triggers>
            </Style>
        </ResourceDictionary>
    </UserControl.Resources>

    <StackPanel Orientation="Vertical">
        <tsf:TsfPopup x:Name="PopupSettings" Topmost="False" Placement="Center">
            <Border CornerRadius="5" BorderThickness="1" Background="White" BorderBrush="Blue" >
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="2*"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>

                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>

                    <TextBlock Text="Alarm Status Refresh Interval (in seconds)" Grid.Column="0" Grid.Row="0"/>
                    <TextBox x:Name="TextBoxRefreshInterval" Grid.Row="0" Grid.Column="1" Width="50"/>

                    <StackPanel Orientation="Horizontal" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" HorizontalAlignment="Right">
                        <Button x:Name="ButtonRestore" Content="Restore Default" Margin="2" Width="Auto" Click="ButtonRestore_Click"/>
                        <Button Content="Cancel" Margin="2" Click="ButtonCancel_Click"/>
                        <Button x:Name="ButtonSave" Content="Save" Margin="2" IsDefault="True" Click="ButtonSave_Click"/>
                    </StackPanel>
                </Grid>
            </Border>
        </tsf:TsfPopup>
        
        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
            <Button x:Name="ButtonDisplaySettings" Content="Display Settings" Template="{StaticResource HyperlinkStyleButtonTemplate}" 
                     Width="Auto" Click="ButtonDisplaySettings_Click"/>
            <TextBlock Text="Refresh Interval: " Width="Auto" />
            <TextBlock x:Name="TextBlockAlarmRefreshInterval" Width="Auto"/>
            <TextBlock Text="{Binding Path=DataContext.LastRefresh, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl, AncestorLevel=1}}" />
        </StackPanel>

        <sdk:DataGrid x:Name="DataGridList" ItemsSource="{Binding CurrentPage}" SelectedItem="{Binding Path=CurrentItem, Mode=TwoWay}" SelectedIndex="{tsfBinding:Column Path=CurrentSelectedIndex}"
                      Height="Auto" Sorting="DataGrid_Sorting" LoadingRow="DataGrid_LoadingRow" SelectionMode="Single" CellStyle="{StaticResource ResourceKey=AlarmCellStyle}">
            <sdk:DataGrid.Columns>
                <sdk:DataGridTextColumn Header="Severity" Width="*" Binding="{tsfBinding:Column Path=Severity}" CellStyle="{StaticResource CenterAlignAlarmCellStyle}" IsReadOnly="True" />
                <sdk:DataGridTextColumn Header="Time Raised" Width="2*" Binding="{tsfBinding:Column Path=TimeRaised}" CellStyle="{StaticResource CenterAlignAlarmCellStyle}" IsReadOnly="True" />
                <sdk:DataGridTextColumn Header="Tag Name" Width="*" Binding="{tsfBinding:Column Path=TagName}" CellStyle="{StaticResource CenterAlignAlarmCellStyle}" IsReadOnly="True" />
                <sdk:DataGridTextColumn Header="Description" Width="4*" Binding="{tsfBinding:Column Path=Description}" IsReadOnly="True" />
            </sdk:DataGrid.Columns>
        </sdk:DataGrid>

        <uc:DataPagerUserControl CurrentPageNumber="{Binding CurrentPageNumber}" PageCount="{Binding PageCount}"
                                 FirstCommand="{Binding FirstCommand}" PreviousCommand="{Binding PreviousCommand}"
                                 NextCommand="{Binding NextCommand}" LastCommand="{Binding LastCommand}"/>
    </StackPanel>
</UserControl>
